package co.cesarcompany.cesarmvc.persistence;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import co.cesarcompany.cesarmvc.domain.Libro;

@Repository
public class DAO {
    
    @Autowired
    private SessionFactory sessionFactory;
    
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Transactional(readOnly = true)
    public List<Libro> findAll() {
        Session session = sessionFactory.getCurrentSession();
        List libros = session.createQuery("from Libro").list();
        return libros;
    }
    
    @Transactional
    public void insertLibro(Libro libro) {
        sessionFactory.getCurrentSession().save(libro);
    }

}
